package com.justnow.offer;

import java.util.ArrayList;
import java.util.List;
import java.util.Stack;

/**
 * @author justnow
 * Created on 2020-09-05
 * Description
 */
public class Haoweilai01 {
    public String notReCuPreOrder (TreeNode root) {
        // write code here
        Stack<TreeNode> stack = new Stack<>();
        stack.add(root);
        StringBuilder stringBuilder = new StringBuilder();
        List<Integer> list = new ArrayList<>();
        while (stack.size() > 0) {
            TreeNode pop = stack.pop();
            list.add(pop.val);
            if (pop.right != null)
                stack.add(pop.right);
            if (pop.left != null)
                stack.add(pop.left);
        }
        int length = list.size();
        for (int i = 0; i < length; i++) {
            if (i == 0)
                stringBuilder.append(list.get(i));
            else
                stringBuilder.append("," + list.get(i));
        }
        return stringBuilder.toString();
    }
}

class TreeNode {
    int val = 0;
    TreeNode left = null;
    TreeNode right = null;
}